package com.wan.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.wan.entity.GameAnnouncement;
import com.wan.service.GameAnnouncementService;
import entity.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author xzx
 * @date 2021/4/14 14:22
 */
@RestController
@RequestMapping("/bs/game")
public class GameGongaoController {

    @Autowired
    private GameAnnouncementService announcementService;

    @RequestMapping("/gonggao/list")
    public ResultBean list(){
        List<GameAnnouncement> gameAnnouncements = announcementService.list();
        List<JSONObject> jsonObjects = gameAnnouncements.stream().map(announcementService -> {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("title",announcementService.getTitle());
            jsonObject.put("cover",announcementService.getCover());
            jsonObject.put("id",announcementService.getId());
            jsonObject.put("auth",announcementService.getAuth());
            jsonObject.put("jianjie",announcementService.getIntroduction());
            return jsonObject;
        }).collect(Collectors.toList());
        return new ResultBean(200,"成功",jsonObjects);
    }

    @RequestMapping("/gonggao/det/{id}")
    public ResultBean det(@PathVariable("id") Integer id){
        GameAnnouncement gameAnnouncement = announcementService.getById(id);
        return new ResultBean(200,"成功",gameAnnouncement);
    }

}
